<?php


$mainCategories = Category::listing("WHERE CAT_IdParent=0 ORDER BY CAT_Libelle");
$status = Status::listing();

// $_POST['status'] == 0 => All categories
$catName= "All";
$statusFilter = isset($_POST['status']) ? ( 0 != $_POST['status'] ?"ART_IdStatut =".$_POST['status']:1):1;
$categoryFilter = isset($_POST['category']) ? (0 != $_POST['category']?"ART_IdCategorie =".$_POST['category']:1 ):1;

if(isset($_POST['category'])) 
{
	$cat = Category::read($_POST['category']);
	
	//Main category with subcategories
	if(0 != $_POST['category'] && 0 == $cat->getIdParentCat())
	{
		$articlesList = Article::listing("WHERE ART_IdCategorie IN(SELECT CAT_Id FROM categories WHERE CAT_IdParent = ".$_POST['category']." AND $statusFilter) ORDER BY ART_Date DESC");
		$catName = $cat->getNameCat();
	}
	else
	{
		$articlesList = Article::listing("WHERE $statusFilter AND  $categoryFilter ORDER BY ART_Date DESC");
		if(0 != $_POST['category']) $catName = $cat->getNameCat(); // 0 = All categories so $cat is null
	}	
	
}
else
	$articlesList = Article::listing("WHERE ART_IdStatut= 2 ORDER BY ART_Date DESC"); // Tous les articles publi&eacute;s




//Pagination
 // $totalArticles = count($articlesList);
// $nbPages=ceil($totalArticles/NB_ARTICLES_PER_PAGE);
// $pagination = false;

// if(count($articlesList)>NB_ARTICLES_PER_PAGE)
// {
	// $pagination = true;
	// include ("partials/list_articles.php");
// }	


include ("partials/list_articles.php");

		
			


?>